<?php
$cs=Yii::app()->clientScript;
$cs->registerCssFile(Yii::app()->request->baseUrl."/css/admin/config.css");
    
$this->breadcrumbs=array();

$this->sidebarTop = array(
    'label' => Yii::t('BackEnd', 'Setting manager'),
    'link' => "#"
);

$this->moduleName = "config";

$this->slidebar = Backend::getModuleSlideBar('Setting', '/config/setting', 'configuration');

//Declare icons
$iconSave = '<img src="'.Yii::app()->request->baseUrl.'/css/admin/images/icons/20_12x12.png" class="icon" />&nbsp;';
$iconReset = '<img src="'.Yii::app()->request->baseUrl.'/css/admin/images/icons/reset_12x12.png" class="icon" />&nbsp;';
$iconTitle = '<img src="'.Yii::app()->request->baseUrl.'/css/admin/images/icons/config_15x15.png" class="icon" />&nbsp;';

$this->menu=array(
    array('label'=>$iconReset.Yii::t('BackEnd', 'Reset'), 'url'=>'javascript:void(0)', 'linkOptions'=>array('onclick'=>'document.getElementById(\'user-setting-form\').reset()')),
    array('label'=>$iconSave.Yii::t('BackEnd', 'Save'), 'url'=>'javascript:void(0)', 'linkOptions'=>array('onclick'=>'document.getElementById(\'user-setting-form\').submit()')),
);

$this->title = $iconTitle.Yii::t('BackEnd', 'Setting');
?>

<div class="wide form">
    <?php $form=$this->beginWidget('CActiveForm', array(
        'id'=>'user-setting-form',
        'enableAjaxValidation'=>false,
    ));
    ?>
    <div class="content-colums">
        <?php
            foreach ($configGroups as $key => $group) {
            $config = new Config();
            $configs = $config->getAllConfig($group->id);
            if(count($configs)>0){
        ?>
        <h1 style="background: none repeat scroll 0 0 #EEEEEE;padding: 5px 0px 5px 5px;" onclick="showHide('<?php echo $group->id?>')"><a href="javascript:void(0);"><?php echo $group->name;?></a></h1>
        <div id="<?php echo $group->id?>" <?php if($key%2 != 0) echo 'style="display: none;"'; else echo 'style="display: block;"'; ?> >
        <?php foreach ($configs as $model) {?>
        <div class="sel-box">
            <h2><?php echo Yii::t('Config', $model->name);?>:</h2>
            <?php
                if($model->html_tag == 'textField'){
                    //echo $form->textField($model,'value',array('size'=>15,'maxlength'=>300));
                    echo CHtml::textField("Configs[$model->id]", $model->value, array('size'=>15,'maxlength'=>300));
                }
                elseif($model->html_tag == 'dateField'){
                        $cs=Yii::app()->clientScript;
                        $cs->registerScriptFile(Yii::app()->request->baseUrl."/js/jquery_ui/jquery-ui-1.8.6.custom.min.js", CClientScript::POS_HEAD);
                        $cs->registerCssFile(Yii::app()->request->baseUrl."/js/jquery_ui/jquery.ui.theme.css");
                        $cs->registerCssFile(Yii::app()->request->baseUrl."/js/jquery_ui/jquery.ui.core.css");
                        $cs->registerCssFile(Yii::app()->request->baseUrl."/js/jquery_ui/jquery.ui.datepicker.css");
                        $cs->registerScriptFile(Yii::app()->request->baseUrl."/js/jquery_ui/jquery.ui.core.min.js", CClientScript::POS_END);
                        $cs->registerScriptFile(Yii::app()->request->baseUrl."/js/jquery_ui/jquery.ui.datepicker.min.js", CClientScript::POS_END);
                        //if(Yii::app()->language == "vi_vn") $cs->registerScriptFile(Yii::app()->request->baseUrl."/js/jquery_ui/i18n/jquery.ui.datepicker-vi.js", CClientScript::POS_END);
                        $cs->registerScript("dateFieldEdit$model->id",'
                            $("#Config_dateFieldValue_'.$model->id.'").datepicker({
                                dateFormat: "dd-mm-yy",
                                //minDate:0,
                                //maxDate:"+1m",
                                buttonImage: baseUrl+"/css/admin/images/calendar.gif",
                                showOn: "both",
                                changeYear:true,
                                changeMonth:true,
                                showAnim: "slideDown"
                            });

                        ', CClientScript::POS_READY);
                    //echo $form->textField($model,'value',array('size'=>15,'maxlength'=>300, 'readOnly'=>'readOnly', 'id'=>"Config_dateFieldValue_$model->id"));
                    echo CHtml::textField("Configs[$model->id]", $model->value, array('size'=>15,'maxlength'=>300, 'readOnly'=>'readOnly', 'id'=>"Config_dateFieldValue_$model->id"));
                }
                else if($model->html_tag == 'textArea'){
                    //echo $form->textArea($model, 'value',array('rows'=>6, 'cols'=>50));
                    echo CHtml::textArea("Configs[$model->id]", $model->value, array('rows'=>6, 'cols'=>25));
                }else if($model->html_tag == 'dropDownList'){
                    //echo $form->dropDownList($model, 'value', ConfigOptionValue::dumpAllValueToArray($model->id));
                    echo CHtml::dropDownList("Configs[$model->id]", $model->value, ConfigOptionValue::dumpAllValueToArray($model->id));
                }else if($model->html_tag == 'radioList'){
                    //echo $form->radioButtonList($model, 'value', ConfigOptionValue::dumpAllValueToArray($model->id));
                    echo CHtml::radioButtonList("Configs[$model->id]", $model->value, ConfigOptionValue::dumpAllValueToArray($model->id));
                }
            ?>
            <br/><br/>
        </div>
        <?php }?>
        <div class="clearfix"></div>
        </div>
<!--        <hr class="dots" />-->
        <?php
        } //end if
        } // end foreach
        ?>
    </div> <!-- e:Content Colums -->
    <?php $this->endWidget(); ?>
</div>

<style type="text/css">
    .ui-datepicker-trigger{margin-bottom: 3px;}
    .content-colums h2 {font: normal 12px arial;}
</style>
<script type="text/javascript">
    function showHide(elementID){
        $('#'+elementID).toggle();
    }
</script>